package com.anjian.bamin.anjiandianzimap.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Chronometer;
import android.widget.TextView;

import com.anjian.bamin.anjiandianzimap.R;
import com.anjian.bamin.anjiandianzimap.model.CompanyInfo;

import java.util.ArrayList;
import java.util.List;


public class MyXunChaAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private ArrayList<Long> mill;
    private OnCompanyClickListener onCompanyClickListener;

    private Context context;
    private List<CompanyInfo> mCompanyInfoList;

    public MyXunChaAdapter(Context context, List<CompanyInfo> mCompanyInfoList,ArrayList<Long> mill) {

        this.context = context;
        this.mCompanyInfoList = mCompanyInfoList;
        this.inflater = LayoutInflater.from(context);
        this.mill = mill;
    }

    @Override
    public int getCount() {
        return mCompanyInfoList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }
    private static class ViewHolder {
        TextView mTextViewName;
        TextView mTextViewAddress;
        Chronometer mChronometer;
        View mLineClick;
    }
    @Override
    public View getView(int position, View inflate, ViewGroup parent) {
        ViewHolder holder = null;
        if (inflate == null) {
            inflate = inflater.inflate(R.layout.xun_cha_item, null);
            holder = new ViewHolder();
            holder.mTextViewName = (TextView) inflate.findViewById(R.id.textViewName);
            holder.mTextViewAddress = (TextView) inflate.findViewById(R.id.textViewAddress);
            holder.mChronometer = (Chronometer) inflate.findViewById(R.id.chronometer);
            holder.mLineClick = inflate.findViewById(R.id.line_click);
            inflate.setTag(holder);
        } else {
            holder = (ViewHolder) inflate.getTag();
        }


        final CompanyInfo companyInfo = mCompanyInfoList.get(position);
        holder.mTextViewName.setText(companyInfo.getCompanyName());
        holder.mTextViewAddress.setText(companyInfo.getCompanyAddress());
        int l = (int) (mill.get(position) / 1000);
        Log.e("getView ", "getView " + l);
        holder.mChronometer.setFormat("%s");
        holder.mChronometer.setBase(mill.get(position));
        holder.mChronometer.start();
        holder.mLineClick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onCompanyClickListener != null) {
                    onCompanyClickListener.onCompanyClick(companyInfo);
                }
            }
        });
        return inflate;
    }
    public void setOnCompanyClickListener(OnCompanyClickListener listener) {
        this.onCompanyClickListener = listener;
    }

    public interface OnCompanyClickListener {
        void onCompanyClick(CompanyInfo companyInfo);
    }





}